package cn.action;

import cn.base.BaseAction;
import cn.domain.PageBean;
import cn.domain.Role;
import cn.service.RoleService;
import cn.utils.HQLHelper;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by jiaxiang Huang on 2017/3/8.
 */
@Controller
@Scope("prototype")
public class RoleAction extends BaseAction<Role> {

    public String findAll(){
//        List<Role> list= roleService.findAll();
//        getValueStack().set("list",list);
        HQLHelper hqlHelper=new HQLHelper(Role.class);
        PageBean pageBean=roleService.getPageBean(hqlHelper,getCurrentPage());
        getValueStack().set("list",pageBean.getRecordList());
        getValueStack().push(pageBean);
        return "list";
    }
    public String delete(){
        roleService.delete(model.getId());
        return "toList";
    }

    /**
     * 跳转至添加页面
     * @return
     */
    public String add(){
        model.setId(0L);
        return "addorupdate";
    }

    /**
     * 添加
     * @return
     */
    public String save(){
        if(model.getId()==0){
            roleService.add(model);
        }
        else {
            roleService.update(model);
        }
        return "toList";
    }
    /**
     *根据id查询跳转修改页面
     */
    public String getById(){
        Role role=roleService.getById(model.getId());
        getValueStack().push(role);
        return "addorupdate";
    }
}
